<?php
session_start();
/*$player = new player;
$rp = new rp;

$standings = $player->get();

$points = $rp->get();

$smarty->assign('standings', $standings);
$smarty->assign('rp', $points);*/

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Datum in het verleden
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                     // Altijd veranderd
header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");                          // HTTP/1.0

ini_set("display_errors", 1); //activeer de display_error

require('./core/Smarty_oRs.php');
require('./includes/config.php');
require('./includes/func_database.php');
require('./includes/func_signups.php');
require('./includes/func_rp.php');
require('./includes/func_raid.php');

$dbh = initConnection();

$signup = new signup;
$rp = new rp;
$raid = new raid;

$smarty = new Smarty_oRs;

$raid_id = $_GET['rid'];

$user_id = $_GET['uid'];

$page_type = $_GET['type'];

$container = $_GET['container'];

$main_signups = $signup->get($raid_id, 0, 0);
$main_subs = $signup->get($raid_id, 0, 1);

$raid_info = $raid->get($raid_id);

$raid_info = $raid_info[0];

$points = $rp->get();

$smarty->assign('rp', $points);

$smarty->assign('user_id', $user_id);

$smarty->assign('raid_info', $raid_info);

$smarty->assign('mains', $main_signups);

$smarty->assign('subs', $main_subs);

$smarty->assign('container', $container);

$smarty->assign('type', $page_type);




$smarty->display('signups_selector.tpl', $_SESSION['uid']);	

switch ($page_type) {
	case 1:
		$smarty->display('signups.tpl', $_SESSION['uid']);	
		break;
	case 2:
		foreach ($main_signups as $single_signup) {
			$role_signups[$single_signup['role_name']]['name'] = $single_signup['role_name'];
			$role_signups[$single_signup['role_name']]['players'][] = $single_signup;			
		}

		foreach ($main_subs as $single_sub) {
			if(empty($single_sub['role_name']))
			{
				$role_subs[$single_sub['role_name']]['name'] = "Unknown";	
			}
			else 
			{
				$role_subs[$single_sub['role_name']]['name'] = $single_sub['role_name'];
			}
				
			$role_subs[$single_sub['role_name']]['players'][] = $single_sub;			
		}
		
		if(count($role_subs) > 0)		
			sort($role_subs);
		
		if(count($role_signups) > 0)
			sort($role_signups);
		
		$smarty->assign('role_subs', $role_subs);
		$smarty->assign('role_signups', $role_signups);
		
		//echo "<pre style='text-align: left;'>";
		//print_r($role_subs);
		//echo "</pre>";
		
		$smarty->display('signups_type.tpl', $_SESSION['uid']);	
		break;
	default:
		$smarty->display('signups.tpl', $_SESSION['uid']);	
		break;
}
?> 
